const jwt=require('jsonwebtoken');
const secret='cara'
function checkToken (req,res,next) {
    let {token} = req.headers;
    jwt.verify(token,secret,(err,decoded)=>{
        if(err){
            res.send({
                code:410,
                msg:'token验证失败',
            })
            return;
        }
        let {time,expire}=decoded;
        let now=Date.now();
        if(now-time>expire){
            res.send({
                code:410,
                msg:'token已过期',
            })
            return;
        }
        next()
    });
   
}
module.exports={checkToken};